package com.codi.bus.core.dao.impl;

import com.codi.base.dao.v2.GeneratedBaseDaoImpl;
import com.codi.bus.core.dao.CdUserShareDao;
import com.codi.bus.core.domain.CdUserShare;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zengxl
 * @Description:
 * @Date: 2018/5/6 17:42
 */
@Repository
public class CdUserShareDaoImpl extends GeneratedBaseDaoImpl<CdUserShare> implements CdUserShareDao{
    @Override
    public CdUserShare selectUserShare(CdUserShare order) {
        return this.getObject("selectUserShare",order);
    }


    /**
     * 慎用
     * @return
     */
    @Override
    public List<CdUserShare> selectAllShare() {
        return this.findList("selectAllShare",null);
    }

    @Override
    public List<CdUserShare> selectOneDayShare(String date) {
        return this.findList("selectOneDayShare",date);
    }

    @Override
    public List<CdUserShare> selectNewShare(Integer userId, String clientId, String tradeAcco, String fundCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        map.put("tradeAcco", tradeAcco);
        map.put("fundCode", fundCode);
        return this.findList("selectNewShare", map);
    }

    @Override
    public List<CdUserShare> selectNewPortfolioShare(Integer userId, String clientId) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        return this.findList("selectNewPortfolioShare", map);
    }

    @Override
    public List<CdUserShare> selectAllOldShare() {
        return this.findList("selectAllOldShare", null);
    }

    @Override
    public void updateShare(CdUserShare cdUserShare) {
        this.update("updateShare",cdUserShare);
    }

    /**
     * 将过期的 很久没有使用的 数据  置为0
     * @param cdUserShare
     */
    @Override
    public void updateShareExpired(CdUserShare cdUserShare) {
        this.update("updateShareExpired",cdUserShare);
    }


    @Override
    public void updateShareOld() {
        this.update("updateShareOld", null);
    }

    @Override
    public void updateShareToday(String createTime) {
        CdUserShare cdUserShare = CdUserShare.builder().createTime(createTime).build();
        this.update("updateShareToday", cdUserShare);
    }

    @Override
    public void changeShareToday(String createTime) {
        CdUserShare cdUserShare = CdUserShare.builder().createTime(createTime).build();
        this.update("changeShareToday", cdUserShare);
    }


    /**
     * 根据用户id和交易账号查询用户份额
     *
     * @param userId
     * @param portfolioTradeAcco
     * @return
     */
    @Override
    public List<CdUserShare> selectByUserIdAndTradeAcco(Long userId, String portfolioTradeAcco) {
        Map<String, Object> params = new HashMap<>();
        params.put("userId", userId);
        params.put("tradeAcco", portfolioTradeAcco);
        return this.findList("selectByUserIdAndTradeAcco", params);
    }
}
